package org.example.platform;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;

@Service
public class MyServiceImpl implements MyService {

    Lock lock = new ReentrantLock();
    @Autowired
    MyMapper myMapper;


    @Override
    public int update(Depart depart) {
        lock.lock();
        try{
            myMapper.update(depart);
            Thread.sleep(5000);
            System.out.println("更新中");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            lock.unlock();
            System.out.println("更新结束");
        }
        return 0;
    }

    @Override
    public int shenHe(Depart depart) {
        lock.lock();
        try{
            myMapper.shenHe(depart);
            Thread.sleep(5000);
            System.out.println("审核中");
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        } finally {
            lock.unlock();
            System.out.println("审核结束");
        }
        return 0;
    }
}
